<?php 
uses("Flay");
echo $html->css(cr("cmsConfig.Backend.siteUrl").'/deals/css/deals.css'); 
?>
<?php 
if(!empty($deals))
{
	$firstTwoDeals = array();
	$firstTwoDeals[] = array_shift($deals);
	$firstTwoDeals[] = array_shift($deals);
	echo $this->element("deals_newsletter_elem",array("firstTwoDeals"=>$firstTwoDeals));
}
foreach($deals as $deal) 
{
	$partialDescription = strip_tags($deal['Deal']['description']);
	$partialDescription = str_replace(array("\n"), "", $partialDescription);
	//$partialDescription = Flay::fragment($partialDescription,200);
	if(strlen($partialDescription) > 200)
	{
		$partialDescriptionArray = explode(" ", $partialDescription);
		$partialDescription = "";
		foreach ($partialDescriptionArray as $pditem)
		{
			if($partialDescription == "")
			{
				$partialDescription = $pditem;
			} else {
				$partialDescription .= " ".$pditem;
			}
			if(strlen($partialDescription) > 190)
			{
				break;
			}
		}
		$partialDescription .= " ...";
	}
	
	$discount = (($deal['Deal']['discount_type'] == Deal::DISCOUNT_TYPE_PERCENT)?$deal['Deal']['discount']."%":number_format((($deal['Deal']['discount']/$deal['Deal']['regular_price'])*100),2)."%");
	
	//$viewButtonImage = cr("cmsConfig.Backend.siteUrl")."/deals/img/deal_newsletter/deal_news_".$deal['Deal']['deal_type'].".gif";
	$viewButtonImage = cr("cmsConfig.Backend.siteUrl")."/deals/img/deal_newsletter/view_deal_button.png";
	$dealViewUrl = cr("cmsConfig.Backend.siteUrl").$deal['Deal']['viewUrl'];
	?>
	<div class="block">
   <table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#f6f4f5" st-sortable="bigimage" id="backgroundTable">
      <tbody>
         <tr>
            <td>
	<table class="mceItemTable" style="border-bottom: 1px solid #cccccc; padding-left: 12px;"
		data-mce-style=" border-bottom: 1px solid #cccccc; padding-left: 12px;"
		bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="8" width="612" align="center" >
		<tbody>
			<tr>
				<td align="left" valign="top" width="187">
					<table class="mceItemTable" border="0" cellpadding="0" cellspacing="0" width="182">
						<tbody>
							<tr>
								<td align="left" height="124" valign="top" width="182">
									<a style="color: #333333; text-decoration: none;"
									href="<?php echo $dealViewUrl ?>"
									target="_blank"
									data-mce-href="<?php echo $dealViewUrl ?>"
									data-mce-style="color: #333333; text-decoration: none;">
										<img
										style="border: 1px solid #cccccc;"
										src="<?php echo cr("cmsConfig.Backend.siteUrl").$deal['Deal']['image'] ?>"
										alt="<?php echo sprintf(__("View %s"),$deal['Deal']['deal_type']); ?>"
										data-mce-src="<?php echo cr("cmsConfig.Backend.siteUrl").$deal['Deal']['image']; ?>"
										data-mce-style="border: 1px solid #cccccc;"
										border="0" height="120" width="180">
									</a><br data-mce-bogus="1">
								</td>
							</tr>
							<tr>
								<td align="left" valign="top" width="182">
									<table class="mceItemTable" bgcolor="#CCCCCC" border="0" cellpadding="0" cellspacing="1" width="182">
										<tbody>
											<tr>
												<td style="border-right: 1px solid #a9a9a9;" data-mce-style="border-right: 1px solid #a9a9a9;"
													align="center" height="27" valign="middle" width="50%">
													<span
													style="font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 1em; font-size: 10px;"
													data-mce-style="font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 1em; font-size: 10px;"><?php echo __("Discount");?><br>
														<strong style="font-size: 13px;" data-mce-style="font-size: 13px;">
														<?php echo $discount; ?>
														</strong>
													</span>
												</td>
												<td align="center"  valign="middle" width="50%">
													<span
													style="font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 1em; font-size: 10px;"
													data-mce-style="font-family: Arial,Helvetica,sans-serif; color: #333333; line-height: 1em; font-size: 10px;"><?php echo __("Price");?><br>
														<strong style="font-size: 13px;" data-mce-style="font-size: 13px;"><?php echo __("$".$deal['Deal']['finalPrice']); ?></strong>
													</span>
												</td>
											</tr>
										</tbody>
									</table>
								</td>
							</tr>
						</tbody>
					</table>
				</td>
				<td align="left" valign="top" width="389">
					<table class="mceItemTable" border="0" cellpadding="0" cellspacing="0" width="380">
						<tbody>
							<tr>
								<td colspan="2" align="left" height="122" valign="top" width="380"  style="padding-top:10px;">
									<a
									style="color: #333333; text-decoration: none;"
									href="<?php echo $dealViewUrl ?>"
									target="_blank"
									data-mce-href="<?php echo $dealViewUrl ?>"
									data-mce-style="color: #333333; text-decoration: none;">
										<span
										style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #333333;"
										data-mce-style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #333333;">
											<strong><?php echo __($deal['Deal']['title']); ?></strong>
										</span>
									</a><br> <br> 
									<span
									style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #333333;"
									data-mce-style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #333333;">
									<?php echo __($partialDescription); ?>
									<br> <br>
									</span>
								</td>
							</tr>
							<tr>
								<td align="left" valign="middle" width="260">&nbsp;</td>
								<td align="right" valign="top" width="120">
								
									<a href="<?php echo $dealViewUrl; ?>" target="_blank" data-mce-href="<?php echo $dealViewUrl; ?>" data-mce-style="text-decoration: none;" style="background-color:#0db9ea; border-top-left-radius:4px; border-bottom-left-radius:4px;border-top-right-radius:4px; border-bottom-right-radius:4px; background-clip: padding-box;font-size:13px; font-family:Helvetica, arial, sans-serif; text-align:center;  color:#ffffff; font-weight: 300; padding:10px 15px;text-decoration:none;"><?php echo __("View"); ?>
												</a>





									<br data-mce-bogus="1">
								</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
		</tbody>
	</table>

	</td>
         </tr>
      </tbody>
   </table>
</div>
<?php } ?>